<template>
  <el-dialog :visible.sync="examineShow" width="800px" @close='dialogClose'
  :close-on-click-modal='false'
  :close-on-press-escape='false' top="10vh">
   <h2 v-if="title" slot="title" class="tx-c">{{title}}</h2>
    <slot></slot>
    <el-form autocomplete="off"  label-width="100px" :model="options" ref="form">
      <el-form-item label="审核结果"  prop="review_status" class="tip">
        <el-radio-group v-model="options.review_status">
          <el-radio :label="1">通过</el-radio>
          <el-radio :label="2">不通过</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="审核意见" v-show="options.review_status === 2" class="tip">
        <el-input
          size="medium"
          type="textarea"
          :autosize='{ minRows: 4, maxRows: 10 }'
          v-model.trim="options.review_comment"
          placeholder="请输入审核意见" />
      </el-form-item>
      <el-form-item label="立项通知书" v-if="options.review_status === 1 && nowProject" class="tip">
        <el-upload style="width: 500px" multiple action="/" :on-change='onChangeFile' :on-remove="onRemoveFile"
          :auto-upload="false" :file-list='file'>
          <el-button size="medium" type="primary">选择文件</el-button>
        </el-upload>
      </el-form-item>
    </el-form>
    <div slot="footer" class="flex-justify-bcenter">
      <el-button @click="examineShow = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
    name:'examineChange',
    props:{
      title:{
        default: '',
      },
      nowProject:{
        default:false,
        type:Boolean,
      }
    },
    data(){
        return{
            examineShow: false,
            options:{
                review_status: null,
                review_comment: null
            },
            file:[],
        }
    },
    methods:{
        dialogClose(){
            this.options.review_status = null
            this.options.review_comment = null
            this.file = []
        },  
        onChangeFile(file, fileList) {
          this.file.push(file)
        },
        onRemoveFile(file, fileList) {
          this.file = fileList
        },
        submit(){
            if(!this.options.review_status){
               this.$message.error('请先选择审核结果')
               return
            }
            if(this.options.review_status === 2 && !this.options.review_comment){
              this.$message.error('请输入审核意见')
              return
            }
            if(this.options.review_status === 1 && this.nowProject && this.file.length === 0){
              this.$message.error('请上传项目立项书')
              return
            }
            let options = {...this.options}
            if(options.review_status === 1) options.review_comment = ''
            if(this.nowProject) options.file = this.file
            options.reviewer_id = this.$store.state.userInfo.employees_id
            this.$emit('submit',options)
            this.examineShow = false
        }
    }
};
</script>
